import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutterproject/mvvm/base/base_controller.dart';
import 'package:flutterproject/page/setting/children/address/data/address_bean.dart';
import 'package:flutterproject/util/address_manager.dart';
import 'package:flutterproject/util/dialog_toast/dialog_util.dart';
import 'package:flutterproject/util/dialog_toast/toast_util.dart';
import 'package:flutterproject/util/http/http_client.dart';
import 'package:flutterproject/util/http/http_exception.dart';
import 'package:get/get.dart';

class AddressController extends BaseController {
  List<AddressBean>? addressList = [];
  HttpClient client = Get.find<HttpClient>();

  @override
  void onReady() {
    super.onReady();
    getAddressData();
  }

  Future getAddressData() async {
    try {
      DialogUtil.showLoading();
      addressList =
          await client.get<List<AddressBean>>(AddressManager.addressAll);
      update();
      return true;
    } on HttpException catch (e) {
      ToastUtil.showFailed(e.message);
      return false;
    } finally {
      DialogUtil.dismiss();
    }
  }
}
